<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="报警编号" prop="caseId">
				<el-input v-model="queryParams.caseId" placeholder="请输入报警编号" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="报警类别" prop="caseType">
				<el-select v-model="queryParams.caseType" placeholder="请输入报警类别" clearable size="small">
					<el-option v-for="dict in caseTypeOptions" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
				</el-select>
			</el-form-item>
			<el-form-item label="学生学号" prop="studentId">
				<el-input v-model="queryParams.studentId" placeholder="请输入报警学生学号" clearable size="small" @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<router-link to="/alarmhistory/alldetail">
					<el-button type="primary" plain icon="el-icon-search" size="mini" v-hasPermi="['system:allalarmhistory']">全部</el-button>
				</router-link>
			</el-col>
			<el-col :span="1.5">
				<router-link :to="{path:'/alarmhistory/pending',query:{ caseStatus: 0 }}">
					<el-button type="info" plain icon="el-icon-plus" size="mini" v-hasPermi="['system:pending']">待处理</el-button>
				</router-link>
			</el-col>
			<el-col :span="1.5">
				<router-link :to="{path:'/alarmhistory/processing',query:{ caseStatus: 1 }}">
					<el-button type="success" plain icon="el-icon-edit" size="mini" v-hasPermi="['system:processing']">进行中</el-button>
				</router-link>
			</el-col>
			<el-col :span="1.5">
				<el-button type="primary" plain icon="el-icon-phone" size="mini" @click="revisited(3)" v-hasPermi="['system:revisited']">待回访</el-button>
			</el-col>
			<el-col :span="1.5">
				<router-link :to="{path:'/alarmhistory/completed',query:{ caseStatus: 4 }}">
					<el-button type="warning" plain icon="el-icon-check" size="mini" v-hasPermi="['system:completed']">已完成</el-button>
				</router-link>
			</el-col>
			<el-col :span="1.5">
				<router-link :to="{path:'/alarmhistory/rejected',query:{ caseStatus: 2 }}">
					<el-button type="danger" plain icon="el-icon-delete" size="mini" v-hasPermi="['system:rejected']">已拒绝</el-button>
				</router-link>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="alarmhistoryList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			<el-table-column label="报警编号" align="center" prop="caseId" />
			<el-table-column label="报警类别" align="center" prop="caseType" />
			<el-table-column label="报警学生所在学院" align="center" prop="studentCollege" />
			<el-table-column label="报警学生学号" align="center" prop="studentId" />
			<el-table-column label="报警时间" align="center" prop="caseFirstTime" />
			<el-table-column label="报警状态" align="center" prop="caseStatus" />
			<el-table-column label="查看详情" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit-outline" @click="details(scope.row)" v-hasPermi="['system:alarmhistory:query']">查看详情</el-button>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
				<template slot-scope="scope">
					<el-button size="mini" type="text" icon="el-icon-edit" @click="deployment(scope.row)" v-hasPermi="['system:alarmhistory:revisited']">回访确认</el-button>
				</template>
			</el-table-column>
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
		 @pagination="getList" />

		<!-- 查看详情对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px">
				<el-form-item label="报警编号" prop="caseId">
					<el-input v-model="form.caseId" :readonly="true" placeholder="请输入报警编号" />
				</el-form-item>
				<el-form-item label="警方备案编号" prop="policeCaseId" v-if="form.policeCaseId !=''">
					<el-input v-model="form.policeCaseId" placeholder="请输入警方备案编号" />
				</el-form-item>
				<el-form-item label="报警类别" prop="caseType">
					<el-input v-model="form.caseType" :readonly="true" placeholder="请输入报警类别" />
				</el-form-item>
				<el-form-item label="报警学生所在学院" prop="studentCollege">
					<el-input v-model="form.studentCollege" :readonly="true" placeholder="请输入报警学生所在学院" />
				</el-form-item>
				<el-form-item label="报警学生学号" prop="studentId">
					<el-input v-model="form.studentId" :readonly="true" placeholder="请输入报警学生学号" />
				</el-form-item>
				<el-form-item label="报警时间" prop="caseFirstTime">
					<el-input v-model="form.caseFirstTime" :readonly="true" placeholder="请输入报警时间" />
				</el-form-item>
				<el-form-item label="警方负责人" prop="policeName">
					<el-input v-model="form.policeName" :readonly="true" />
				</el-form-item>
				<el-form-item label="学院负责人" prop="collegeName">
					<el-input v-model="form.collegeName" :readonly="true" />
				</el-form-item>
				<el-form-item label="报警内容" prop="caseContent">
					<el-input v-model="form.caseContent" :readonly="true" type="textarea" :rows="2" placeholder="请输入报警内容" />
				</el-form-item>
				<el-form-item label="报警图片" prop="casePic">
					<div v-for="casePic in this.form.casePic" >
						<img :src="casePic" alt="暂无图片" style="width: 350px;">
					</div>
				</el-form-item>
			</el-form>
		</el-dialog>
		<!-- 回访确认对话框 -->
		<el-dialog :title="titlereturnVisit" :visible.sync="returnVisitopen" width="500px" append-to-body>
			<el-form ref="returnVisitform" :model="returnVisitform" :rules="deploymentrules" label-width="80px">
				<el-form-item label="回访人员警号" prop="caseReturnVisitId">
					<el-select v-model="returnVisitform.caseReturnVisitId" placeholder="请选择回访人员警号" clearable size="small">
						<el-option v-for="dict in returnVisitOptions" :key="dict.userId" :value="[dict.userId,dict.userName]" />
					</el-select>
				</el-form-item>
				<el-form-item label="回访内容" prop="caseReturnVisitContent">
					<el-input v-model="returnVisitform.caseReturnVisitContent"  type="textarea" :rows="2" placeholder="请输入回访内容" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="returnvisit">回访确认</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import {
		listAlarmhistory,
		Alarmhistorydetails,
		returnVisit,
		SelectPoliceCaseId
	} from "@/api/system/alarmhistory";
	import Editor from '@/components/Editor';
	import store from '@/store'

	export default {
		name: "Advertisementinfo",
		components: {
			Editor,
		},
		data() {
			return {
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 广告信息表格数据
				alarmhistoryList: [],
				//报警类别字典
				caseTypeOptions: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				//调配处理标题
				titlereturnVisit: "",
				//回访负责人员警号列表
				returnVisitOptions: [],
				//是否显示调配处理
				returnVisitopen: false,
				//详情caseId
				casedetails: {
					caseId: null
				},
				//回访处理form
				returnVisitdetails: {},
				//确认回访按钮
				returnform: {},
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					caseId: null,
					policeCaseId: null,
					caseType: null,
					studentCollege: null,
					studentId: null,
					caseFirstTime: null,
					caseStatus: null,
					userUnity: null,
					userId: null
				},
				//拒绝处理案件参数
				refusequeryParams: {
					caseId: null,
					caseStatus: null
				},
				// 查看详情表单参数
				form: {},
				// 查看详情表单校验
				rules: {},
				//回访处理表单参数
				returnVisitform: {},
				//查看调配处理表单校验
				deploymentrules: {
					caseReturnVisitId: [{
						required: true,
						message: "回访人员警号不能为空",
						trigger: "blur"
					}],
					caseReturnVisitContent: [{
						required: true,
						message: "回访内容不能为空",
						trigger: "blur"
					}]
				}
			};
		},
		created() {
			this.getList();
			this.getDicts("case_type").then(response => {
				this.caseTypeOptions = response.data;
			});
		},
		methods: {
			/** 查询报警历史列表 */
			getList() {
				this.loading = true;
				let status = this.$route.query.caseStatus;
				this.queryParams.userUnity = store.getters.userroles.roleId;
				this.queryParams.userId = store.getters.userId;
				this.queryParams.caseStatus = status;
				listAlarmhistory(this.queryParams).then(response => {
					this.alarmhistoryList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.returnVisitopen = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					caseId: null,
					policeCaseId: null,
					caseType: null,
					studentCollege: null,
					studentId: null,
					caseFirstTime: null,
					caseStatus: null,
					userUnity: null,
					userId: null,
					caseReturnVisitContent: null,
					collegeName: null,
					caseReturnVisitTime: null,
					policeName: null,
					caseContent: null,
					caseReturnVisitName: null
				};
				this.resetForm("form");
			},
			resetreturnVisitform() {
				this.returnVisitform = {
					caseId: null,
					policeCaseId: null,
					caseType: null,
					studentCollege: null,
					studentId: null,
					caseFirstTime: null,
					caseStatus: null,
					userUnity: null,
					userId: null,
					caseReturnVisitContent: null,
					collegeName: null,
					caseReturnVisitTime: null,
					policeName: null,
					caseContent: null,
					caseReturnVisitName: null
				};
			},
			//待回访按钮
			revisited(status) {
				this.queryParams.caseStatus = status;
				this.getList();
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.advertisementId)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			/** 查看详情按钮操作 */
			details(row) {
				this.reset();
				this.casedetails.caseId = row.caseId || this.ids
				Alarmhistorydetails(this.casedetails).then(response => {
					this.form = response.rows[0];
					this.open = true;
					this.title = "报警详情";
				});
			},
			/* 回访确认按钮 */
			deployment(row) {
				this.resetreturnVisitform();
				this.returnVisitdetails.caseId = row.caseId || this.ids
				SelectPoliceCaseId(this.returnVisitdetails).then(response => {
					this.returnVisitOptions = response.rows[0].policeInfo;
					this.returnform.caseId = row.caseId;
					this.returnVisitopen = true;
					this.titlereturnVisit = "回访信息";
				});
			},
			//确认完成回访按钮
			returnvisit() {
				this.$refs["returnVisitform"].validate(valid => {
					if (valid) {
						this.returnform.caseReturnVisitId = this.returnVisitform.caseReturnVisitId[0];
						this.returnform.caseReturnVisitContent = this.returnVisitform.caseReturnVisitContent;
						if (this.returnform.caseId != null) {
							returnVisit(this.returnform).then(response => {
								this.msgSuccess("回访确认成功!");
								this.returnVisitopen = false;
								this.getList();
							});
						} else {
							this.msgInfo("请选择一个案件！");
							this.returnVisitopen = false;
							this.getList();
						}
					}
				});
			},
		}
	};
</script>
